package com.pshdhx.aiagent.rag;

import com.alibaba.cloud.ai.advisor.DocumentRetrievalAdvisor;
import com.alibaba.cloud.ai.dashscope.api.DashScopeApi;
import com.alibaba.cloud.ai.dashscope.rag.DashScopeDocumentRetriever;
import com.alibaba.cloud.ai.dashscope.rag.DashScopeDocumentRetrieverOptions;
import org.springframework.ai.chat.client.advisor.api.Advisor;
import org.springframework.ai.rag.retrieval.search.DocumentRetriever;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author pansd
 * @Date 2025-07-04 9:34
 * @Des
 */
@Configuration
public class LoveAppRagCloudConfig {

    @Value("${spring.ai.dashscope.api-key}")
    private DashScopeApi dashScopeApiKey;

    private String CloudName = "恋爱知识问答";


    @Bean
    Advisor dashScopeRagCloudAdvisor() {
        DocumentRetriever retriever = new DashScopeDocumentRetriever(dashScopeApiKey,
                DashScopeDocumentRetrieverOptions.builder().withIndexName(CloudName).build());
        DocumentRetrievalAdvisor documentRetrievalAdvisor = new DocumentRetrievalAdvisor(retriever);
        return documentRetrievalAdvisor;
    }
}
